package com.github.wujichen158.andemusic.aboutconfig;

import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;

public class AndeMusicConfig {
    public static String defaultMusicName;
    public static int minWaitTime;
    public static int maxWaitTime;
    public static boolean isOpCommands;
    public static String defaultTitleMusicName;

    private static final String GENERAL_CTG = "general";

    public static void init(FMLPreInitializationEvent event) {
        Configuration config = new Configuration(event.getSuggestedConfigurationFile());
        config.load();
        defaultMusicName = config.get(GENERAL_CTG, "defaultMusicName", "music_none", "Default music name").getString();

        minWaitTime = config.get(GENERAL_CTG, "minWaitTime", 30, "Minimum wait tick time for next sound playing.(default:30,tick)").getInt();
        maxWaitTime = config.get(GENERAL_CTG, "maxWaitTime", 60, "Maximum wait tick time for next sound playing.(default:60,tick)").getInt();
        waitTimePostProcess();

        isOpCommands = config.get(GENERAL_CTG, "isOpCommands", false, "Are all commands only used by OP?(default:false)").getBoolean();
        defaultTitleMusicName = config.get(GENERAL_CTG, "defaultTitleMusicName", "music_none", "Default music ID when you are on the game interface,this only effects on client.").getString();
        config.save();
    }

    private static void waitTimePostProcess() {
        minWaitTime = Math.max(minWaitTime, 0);
        maxWaitTime = Math.max(maxWaitTime, 0);
        if (minWaitTime > maxWaitTime) {
            int temp = minWaitTime;
            minWaitTime = maxWaitTime;
            maxWaitTime = temp;
        }
    }
}